home *** CD-ROM | disk | FTP | other *** search
- // This code was written Thursday June 22, 1992 by Jorg 'jbx' Brown.
- // This code is not freeware; this code is public domain.
-
- // Written in Think C 5.0. Anything less would be unthinkable.
-
- #undef SystemSevenOrLater
- #define SystemSevenOrLater 1
-
- #include "Misc.h"
- #include <GestaltEqu.h>
- #include <PPCToolbox.h>
- #include <EPPC.h>
- #include <AppleEvents.h>
-
- static PPCOpenPBRec PPCOpenRec;
- static PPCPortRec PPCPort, otherPort;
- static LocationNameRec LNR, otherLoc;
-
- static short PPC_waiting = 1;
- static short call_inform = 0;
- static char buffer[512];
- static short new_mouse;
- PPCInformPBRec Informant;
- short whichReader = 1;
- PPCReadPBRec Reader1, Reader2;
-
- static void pJGNEFilter(void);
-
- void main(void) {
- short i;
-
- SetA4(&main);
- asm {
- lea @pj+2,a0
- move.l JGNEFilter,(a0)
- bne.s @nrm
- move.w #0x4E75,-2(a0)
- nrm: lea @ptch,a0
- move.l a0,JGNEFilter
- };
-
- DetachResource(RecoverHandle(&main));
-
- for (i = 1000; i < 1006; i++) {
- ShowINIT(0, i);
- jbxDelay(15);
- }
- ShowINIT(1006, 0);
-
- for (i = 2000; i < 2004; i++) {
- ShowINIT(0, i);
- jbxDelay(15);
- }
- ShowINIT(2004, 0);
-
- return;
-
- if (0) asm { /* let's not execute the patch code, shall we? */
- ptch: cmpi.w #nullEvent,OFFSET(EventRecord, what)(a1)
- bne @pj
- movem.l a0-a1/a4/d0-d2,-(a7)
- lea main,a4
- move.l a1,-(a7)
- jsr pJGNEFilter
- addq #4,a7
- movem.l (a7)+,a0-a1/a4/d0-d2
- cmpi.w #nullEvent,OFFSET(EventRecord, what)(a1)
- beq.s @pj
- moveq #1,d0
- move.w d0,4(a7)
- pj: jmp 0x12345678
- }
- }
-
- extern Point Mouse : 0x830;
- extern char MBState : 0x172;
- extern char CrsrBusy : 0x8CD;
- extern char CrsrVis : 0x8CC;
- extern char CrsrObscure : 0x8D2;
-
- static void InformHappened(void) {
- PPCReadPBRec *px;
- asm {
- movem.l a0/a1/a4/d0/d1/d2,-(a7)
- lea main,a4
- }
-
- px = &Reader1;
- if (whichReader == 2) {
- px = &Reader2;
- }
- if (px->ioResult == noErr) {
- if (px->actualLength == 6) {
- struct {
- Point ms;
- short down;
- } MouseData;
- BlockMove(&buffer, &MouseData, sizeof(MouseData));
-
- if (MouseData.ms.h < CrsrPin.left) MouseData.ms.h = CrsrPin.left;
- if (MouseData.ms.h > CrsrPin.right) MouseData.ms.h = CrsrPin.right;
-
- if (MouseData.ms.v < CrsrPin.top) MouseData.ms.v = CrsrPin.top;
- if (MouseData.ms.v > CrsrPin.bottom) MouseData.ms.v = CrsrPin.bottom;
-
- // incoming message!
- if (MouseData.ms.v != Mouse.v || MouseData.ms.h != Mouse.h) {
- if (!CrsrBusy) {
- short hide = 0;
- if (CrsrVis && !CrsrObscure) {
- hide = 1;
- HideCursor();
- }
- *(Point *)0x828 = MouseData.ms;
- *(Point *)0x82C = MouseData.ms;
- *(Point *)0x830 = MouseData.ms;
- if (hide || CrsrObscure) {
- ShowCursor();
- }
- }
- }
- } else if (px->actualLength == sizeof(EventRecord)) {
- EvQElPtr eqp;
- EventRecord er = *(EventRecord *)&buffer;
- if (er.what == mouseDown && MBState < 0) {
- MBState &= 0x7F;
- } else if (er.what == mouseDown && MBState < 0) {
- MBState |= 0x80;
- }
- PPostEvent(er.what, er.message, &eqp);
- // eqp->evtQWhat = er.what;
- // eqp->evtQMessage = er.message;
- eqp->evtQWhere = er.where;
- eqp->evtQModifiers = er.modifiers;
- if (er.what == mouseDown && MBState < 0) {
- MBState &= 0x7F;
- } else if (er.what == mouseDown && MBState < 0) {
- MBState |= 0x80;
- }
- }
- px->actualLength = 20;
- } else if (px->ioResult == sessClosedErr) {
- px->ioResult = noErr;
- Informant.ioCompletion = (void *)&InformHappened;
- Informant.portRefNum = PPCOpenRec.portRefNum;
- Informant.autoAccept = TRUE;
- Informant.portName = &otherPort;
- Informant.locationName = &otherLoc;
- Informant.userName = 0;
- PPC_waiting = PPCInformAsync(&Informant);
- goto inform;
- }
-
- new_mouse = 1;
- whichReader = 3 - whichReader;
-
- px = &Reader1;
- if (whichReader == 2) {
- px = &Reader2;
- }
-
- px->ioCompletion = &InformHappened;
- px->sessRefNum = Informant.sessRefNum;
- px->bufferPtr = buffer;
- px->bufferLength = sizeof(EventRecord);
- px->actualLength = 0;
- PPCReadAsync(px);
-
- inform:
- asm {
- movem.l (a7)+,a0/a1/a4/d0/d1/d2
- }
- }
-
- static void pJGNEFilter(void) {
- long PPC_flags;
-
- if (PPC_waiting < 0) return;
- if (PPC_waiting == 1) {
- if (Gestalt(gestaltPPCToolboxAttr, &PPC_flags) != noErr) return;
- if (!(PPC_flags & gestaltPPCSupportsRealTime)) return;
- Reader1.ioResult = 1;
- Reader2.ioResult = 2;
-
- PPCPort.nameScript = 0; // smRoman;
- PStringMove("\pNetMouse - pick ME!", PPCPort.name);
- PPCPort.portKindSelector = ppcByString;
- PStringMove("\pMac Hax", PPCPort.u.portTypeStr);
- // PPCPort.u.port.creator
- // PPCPort.u.port.type
-
- PPCOpenRec.ioCompletion = 0;
- PPCOpenRec.serviceType = ppcServiceRealTime;
- PPCOpenRec.resFlag = 0;
- PPCOpenRec.portName = &PPCPort;
- PPCOpenRec.locationName = 0;
- PPCOpenRec.networkVisible = true;
- PPC_waiting = PPCOpenSync(&PPCOpenRec);
- if (PPC_waiting != noErr) return;
-
- Informant.ioCompletion = (void *)&InformHappened;
- Informant.portRefNum = PPCOpenRec.portRefNum;
- Informant.autoAccept = TRUE;
- Informant.portName = &otherPort;
- Informant.locationName = &otherLoc;
- Informant.userName = 0;
- PPC_waiting = PPCInformAsync(&Informant);
- return;
- }
- }